#! /usr/bin/perl
#
# resucedsnapshot.pl creates a reduced portage snapshot based on a
# dfault set (eclasses, profiles) and a packagelist created by
# packlister.pl.
#
# Usage: packlister.pl <version> | reducedsnapshot.pl
#        reducedsnapshot.pl packlisterfile
#        reducedsnapshot.pl < packlisterfile

@minportage = ( 
	"portage/eclass",
	"portage/profiles/arch.list",
	"portage/profiles/base",
	"portage/profiles/categories",
	"portage/profiles/desc",
	"portage/profiles/default-linux",
	"portage/profiles/info_pkgs",
	"portage/profiles/info_vars",
	"portage/profiles/lang.desc",
	"portage/profiles/package.mask",
	"portage/profiles/profiles.desc",
	"portage/profiles/thirdpartymirrors",
	"portage/profiles/uclibc",
	"portage/profiles/updates",
	"portage/profiles/use.desc",
	"portage/profiles/use.local.desc"
);

print "Building package list...\n";
$version = <>;
chop $version;
while (<>)
{
	($pack,$ver,,,,) = split;
	push (@minportage, "portage/$pack");
	push (@minportage, "portage/metadata/cache/$pack-$ver");
}

print "Extracting portage...\n";
system "mkdir tmp_port";
system "tar jx -C tmp_port -f /var/tmp/catalyst/snapshots/portage-$version.tar.bz2";
print "Creating reduced portage snapshot...\n";
system "tar jc -C tmp_port -f redportage-$version.tar.bz2 @minportage";
print "Cleaning up...\n";
system "rm -rf tmp_port";
print "Done.\n";
